<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>

<html>
  <head>
  	<meta charset="utf-8">
  	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>调度</title>
	<meta name="decorator" content="default"/>
	<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
	
	<script type="text/javascript">
		var browser = {
	        versions: function() {
	            var u = navigator.userAgent,
	            app = navigator.appVersion;
	            return {
	                mobile: !!u.match(/AppleWebKit.*Mobile.*/),
	                ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
	                android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
	                iPhone: u.indexOf("iPhone") > -1,
	                iPad: u.indexOf("iPad") > -1
	            };
	        } (),
	        language: (navigator.browserLanguage || navigator.language).toLowerCase()
	    };
	</script>

	
    <script type="text/javascript">
		$(document).ready(function() {
			
			$("#close,#btnCancel").click(function(){
	        	$(".tan").addClass("hide");
	        });
		
			$("#dispachFrom").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});					
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        function getLocalTime(nS) {     
		   return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');     
		}
        /**
        * id 运单id
        * persion 联系人
        * tell 联系电话
        * tbGoodsReceiptCompany 收货方
        * goodName 货物名称
        * weight 重量
        */
        function zhipai(id){
        	var row_invoice_info_countext_Two = "";
   			var row_invoice_info_countext_Three = "";
        	$("#applyId").val(id);
        	$.ajax({
        		url:"${ctx}/tb_waybill/tbWaybill/dispatch/findDetailById",
        		type:"post",
        		data:{
        			id:id
        		},
        		dataType:"json",
        		success:function(data){
        			var weight = "";
        			var goodName =  "";
        			var tbGoodsReceiptCompany = "";
        			if(data != null && typeof(data) != "undefined"){
        				weight += data.tbWaybillDetailOne.weight+"吨";
        				goodName +=data.tbWaybillDetailOne.tbGoods.goodName;
        				tbGoodsReceiptCompany+=data.tbWaybillDetailOne.tbDischargeCargoAddress.shortName;
        				$("#id").val(data.id);
        				var weightTwo = '';
        				var goodNameTwo =  '';
        				var tbGoodsReceiptCompanyTwo ='';
        				var weightThree = '';
        				var goodNameThree =  '';
        				var tbGoodsReceiptCompanyThree = '';       				
        				var tbWaybillDetailTwo = data.tbWaybillDetailTwo;
        				var tbWaybillDetailThree = data.tbWaybillDetailThree;
        				if(tbWaybillDetailTwo != null && typeof(tbWaybillDetailTwo) != "undefined"){
        					weightTwo = data.tbWaybillDetailTwo.weight;
        					goodNameTwo =  data.tbWaybillDetailTwo.tbGoods.goodName;
        					tbGoodsReceiptCompanyTwo =data.tbWaybillDetailTwo.tbDischargeCargoAddress.shortName;
        					row_invoice_info_countext_Two +=
	        				'<div class="col-sm-4 invoice-col">'+
						          '二、'+
						          '<address>'+
						            	'品名:'+goodNameTwo+'<br>'+
						           		'重量:'+weightTwo+'<br>'+
						           		'地址:'+tbGoodsReceiptCompanyTwo+
						          '</address>'+
					        '</div>';
        					
        				}
        				if(tbWaybillDetailThree != null && typeof(tbWaybillDetailThree) != "undefined"){
        					
        					weightThree =data.tbWaybillDetailThree.weight;
        					goodNameThree =  data.tbWaybillDetailThree.tbGoods.goodName;
        					tbGoodsReceiptCompanyThree = data.tbWaybillDetailThree.tbDischargeCargoAddress.shortName;
        				
        					row_invoice_info_countext_Three +=
	        				'<div class="col-sm-4 invoice-col">'+
						          '三、'+
						          '<address>'+
						            	'品名:'+goodNameThree+'<br>'+
						           		'重量:'+weightThree+'<br>'+
						           		'地址:'+tbGoodsReceiptCompanyThree+
						          '</address>'+
					        '</div>';
        					
        				}
        				var outCarTime = data.outCarTime;
        				var row = '<div class="row">'+
								        '<div class="col-xs-12">'+
								          '<h4 class="page-header">'+
								            '<i class="fa fa-truck"></i> '+ data.tbCarInfo.carCode +'|'+data.tbCarInfo.carGCode+
								           '<small class="pull-right">出车时间:'+getLocalTime(outCarTime)+'</small>'+
								         ' </h4>'+
								        '</div>'+
								      '</div>';
						var row_invoice_info = '<div class="row invoice-info">';
        				var row_invoice_info_end = '</div>';
        				var row_invoice_info_countext_One = ''+
        				'<div class="col-sm-4 invoice-col">'+
					          '一、'+
					          '<address>'+
					            	'品名:'+goodName+'<br>'+
					           		'重量:'+weight+'<br>'+
					           		'地址:'+tbGoodsReceiptCompany+
					          '</address>'+
				        '</div>';
				        var str = ""+
	        				row_invoice_info+
	        				row_invoice_info_countext_One+
	        				row_invoice_info_countext_Two+
	        				row_invoice_info_countext_Three+
	        				row_invoice_info_end;
        				$("#invoice_context").html(row);
        				$("#invoice_context").append(str);
        				
        				/* $("#goodName").html(goodName);
        				$("#weight").html(weight);
        				$("#tbGoodsReceiptCompany").html(tbGoodsReceiptCompany); */
        				
        				$("#formDispach").removeClass("hide");
					    $("#mask").removeClass("hide");
        				if(browser.versions.mobile){
					    	$("#formDispach").removeClass("hide");
					    	$("#mask").removeClass("hide");
        					//$(".formDispach").css({"width":"100%","top":"0px","left":"0px"});
        					$(".formDispach").attr("style","width:100%;top:0px;left:0px;")
					    }      				
        				$(".tan").removeClass("hide");
        			}
        		},
        		error:function(){
        			
        		}
        	});
        	
        	
        	
        }
       
        
	</script>
	<style type="text/css">
		/*弹窗样式*/
		#mask{
            background: #000;
            opacity: 0.75;
            /*IE兼容*/
            filter: alpha(opacity=75);
            height: 1000px;
            width: 100%;
            position: absolute;
            left: 0;
            top: 0;
            z-index: 1099;
          }
          #formDispach{
            position: fixed;
             left: 30%;
            top: 5%;
            z-index:1100;
          }
          .formCon{
            width: auto;
            height: auto;
            background: #FFF;
            position: relative;
          }
	</style>
  </head>
  
  <body class="hold-transition  sidebar-mini">
  
  <%--弹出层 --%>
  	<div class="tan hide" id="mask"></div>
	<div class="tan hide" id="formDispach">
		<div class="formCon">
			<form:form id="inputForm" modelAttribute="tbWaybill"  action="${ctx }/tb_waybill/tbWaybill/dispatch/form" method="post" class="sidebar-form">
					<form:hidden path="id"/>
			        <div class="input-group">
			          <div class="modal-dialog">
					  	 <div class="modal-content">
					          <div class="modal-header">
					            <button type="button" class="close" data-dismiss="modal" aria-label="Close"  >
					              <span aria-hidden="true">&times;</span></button>
					            <h4 class="modal-title">出车登记</h4>
					          </div>
					          <div class="modal-body">
					            	<section class="invoice" id="invoice_context">
					            		<div class="col-md-6">
		             							<div class="form-group">
		             							    <from:input id="id" type="hidden" value="" path="id"/>	
		             							</div>
		             						</div>
					            	</section>
				            	<section class="content">
					            	<div class="box box-default">
					            		<div class="box-body">
					            			<div class="row">
					            				 	<div class="form-group">
		           										<label>司机一：</label>
		           										<form:select id="driverId" path="tbDriver.id" class="form-control" style="width: 100%;">
															<form:option  value="" label=""/>
															<form:options items="${driver}" itemValue="id" itemLabel="driverName" htmlEscape="false"/>
														</form:select>
		           									</div>
		           									<div class="form-group">
		           										<label>司机二：</label>
		           										<form:select id="driverTwoId" path="tbDriverTwo.id" class="form-control" style="width: 100%;">
															<form:option  value="" label=""/>
															<form:options items="${driver}" itemValue="id" itemLabel="driverName" htmlEscape="false"/>
														</form:select>
		              								</div>
					            			</div>
					            		</div>
					            	</div>
					      		 </section>
					          </div>
					          <div class="modal-footer">
					            <button type="button" class="btn btn-default pull-left closeBtn" data-dismiss="modal" >取消</button>
					            <button type="submit" class="btn btn-primary">提交</button>
					          </div>
					        </div>
				        </div>
		  			</div>
		      </form:form>
		</div>
	</div>
  <%--弹出层 end--%>
  
  
  
  
  
  <section class="content">
      <div class="row">
        <div class="col-xs-12">
			  <div class="box">
			  	<div class="box-header">
			      <h3 class="box-title">司  机  调  度</h3>
			    </div>
				<sys:message content="${message}"/>
				<div class="box-body">
					<table id="example1" class="table table-striped table-bordered">
						<thead>
							<tr>
								<th>#</th>
								<th>出车时间</th>
								<th>托运方</th>
								<th colspan="2">装货地址</th>
								<th colspan="3">收货单位</th>
								<th colspan="3">收货地址</th>
								<th colspan="3"colspan="3">品名</th>
								<th colspan="3">重量(吨/t)</th>
								<shiro:hasPermission name="tb_waybill:tbWaybill:edit"><th>操作</th></shiro:hasPermission>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.list}" var="tbWaybill"  varStatus="status">
								<tr>
									<td>${status.count} </td>
									<td><fmt:formatDate value="${tbWaybill.outCarTime}" pattern="yyyy-MM-dd"/></td>
									<td>${tbWaybill.tbGoodsConsignmentCompany.shortName}</td>
									<%--装货地址 --%>
								<td>${tbWaybill.tbLoadingAddress.shortName}</td>
								<td>${tbWaybill.tbLoadingAddressTwo.shortName}</td>
								<%--装货地址 end--%>
								<%--收货公司 --%>
								<td>${tbWaybill.tbWaybillDetailOne.tbGoodsReceiptCompany.name}</td>
								<td>${tbWaybill.tbWaybillDetailTwo.tbGoodsReceiptCompany.name}</td>
								<td>${tbWaybill.tbWaybillDetailThree.tbGoodsReceiptCompany.name}</td>
								<%--收货公司 结束--%>
								<%--收货地址 --%>
								<td>${tbWaybill.tbWaybillDetailOne.tbDischargeCargoAddress.name}</td>
								<td>${tbWaybill.tbWaybillDetailTwo.tbDischargeCargoAddress.name}</td>
								<td>${tbWaybill.tbWaybillDetailThree.tbDischargeCargoAddress.name}</td>
								<%--收货地址 end--%>
								<%--品名 --%>
									<td>${tbWaybill.tbWaybillDetailOne.tbGoods.goodName}</td>
									<td>${tbWaybill.tbWaybillDetailTwo.tbGoods.goodName}</td>
									<td>${tbWaybill.tbWaybillDetailThree.tbGoods.goodName}</td>
								<%--品名 end--%>
								<%--重量 --%>
								<td>${tbWaybill.tbWaybillDetailOne.weight}</td>
								<td>${tbWaybill.tbWaybillDetailTwo.weight}</td>
								<td>${tbWaybill.tbWaybillDetailThree.weight}</td>
								<%--重量 end--%>
									<%-- <td>${tbWaybill.tbWaybillDetailOne.tbDischargeCargoAddress.persion }(${tbWaybill.tbWaybillDetailOne.tbGoodsReceiptCompany.tell })</td>
									<td>${tbWaybill.tbWaybillDetailTwo.tbDischargeCargoAddress.persion }(${tbWaybill.tbWaybillDetailTwo.tbGoodsReceiptCompany.tell })</td>
									<td>${tbWaybill.tbWaybillDetailThree.tbDischargeCargoAddress.persion }(${tbWaybill.tbWaybillDetailThree.tbGoodsReceiptCompany.tell })</td> --%>
									<shiro:hasPermission name="tb_waybill:tbWaybill:edit"><td><a href="javascript:void(0);"  onclick="zhipai(
									'${tbWaybill.id}')">指派</a></td></shiro:hasPermission>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<ul class="pagination">${page}</ul>
				</div>
			</div>
		</div>
	</div>
</section>
	
	<!-- jQuery 2.2.3 -->
<script src="${adminLET }/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${adminLET }/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${adminLET }/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${adminLET }/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="${adminLET }/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${adminLET }/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${adminLET }/dist/js/app.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="${adminLET }/dist/js/demo.js"></script>
<!-- page script -->
<script>
  $(function () {
  
			$(".close,.closeBtn").click(function(){
				$("#formDispach").addClass("hide");
			    $("#mask").addClass("hide");
			});
  	
    $("#example2").DataTable({
    	"paging": true,
     	 "lengthChange": false,
     	 "searching": false,
     	 "ordering": true,
     	 "info": true,
      	"autoWidth": false,
    	"oLanguage": {  
			"sLengthMenu": "每页显示 ${page.pageSize}条",  
			"sZeroRecords": "没有找到符合条件的数据",  
			//"sProcessing": "&lt;img src=’./loading.gif’ /&gt;",  
			"sInfo": "当前第 ${page.pageNo}条　共计 ${page.count} 条",  
			"sInfoEmpty": "木有记录",  
			//"sInfoFiltered": "(从 _MAX_ 条记录中过滤)",  
			//"sSearch": "搜索：",  
			"oPaginate": {  
				"sFirst": "首页",  
				"sPrevious": "前一页",  
				"sNext": "后一页",  
				"sLast": "尾页"  
			}  
		} 
    
    
    });
   
  });
</script>
	
  </body>
</html>
